package mo.offer_special;

import mo.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class L055 {

    private List<Integer> nodes = new ArrayList<>();
    private int idx = 0;

    public L055(TreeNode root) {
        dfs(root);
    }

    private void dfs(TreeNode root) {
        if (root != null) {
            dfs(root.left);
            nodes.add(root.val);
            dfs(root.right);
        }
    }

    public int next() {
        return nodes.get(idx++);
    }

    public boolean hasNext() {
        return idx < nodes.size();
    }

}
